﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace THenu.BasicKnowledge
{
    public class XmlSerializa
    {
        public void SerializableTest()
        {

            Company cp = new Company();
           
            

            List<Person> list = new List<Person>();
            list.Add(new Person("MISS DD", 20, Sex.Female, LocoDirection.Left));
            list.Add(new Person("MR.  DD", 19, Sex.Male, LocoDirection.Right));
           
            cp.Leader = new Person("MRS DDL", 23, Sex.Unknow, LocoDirection.Right);
            cp.PersonList = list;
            cp.Count = 5;
            XmlSerializer xmlSe = new XmlSerializer(typeof(Company));
            using (FileStream fileOS = File.Open("C:\\XmlTest.xml", FileMode.Create))
            {
                xmlSe.Serialize(fileOS, cp);
            }

            using (FileStream fileOS = File.Open("C:\\XmlTest.xml", FileMode.Open))
            {
                Company comp = (Company)xmlSe.Deserialize(fileOS);

                Console.WriteLine(comp.PersonList.Count);
            }

        }


    }
    [Serializable]
    public class Company
    {
        [XmlElement]
        public int Count { get; set; }
        public List<Person> PersonList { get; set; }
        public Person Leader { get; set; }
    }
    public class PersionList
    {
        public List<Person> Persons { get; set; }
    }
}
